package com.gzhryc.shared_device.oem.code.business.dao.db;

import com.gzhryc.common.NumberTools;
import com.gzhryc.common.StringTools;
import com.gzhryc.jdbc.annotaion.Column;
import com.gzhryc.jdbc.annotaion.Id;
import com.gzhryc.jdbc.annotaion.JoinField;
import com.gzhryc.jdbc.annotaion.Table;
import com.gzhryc.shared_device.base.enums.ECouponType;
import com.gzhryc.shared_device.oem.code.business.EBusinessType;
import com.gzhryc.shared_device.oem.code.business.dao.enums.CouponActivityEnum;

import java.util.Date;

/**
 * 优惠活动
 */
@Table(name = "business_coupon_activity")
public class CouponActivity {

    @Id(autoIncrement = 10000)
    @Column
    protected Long id;

    @Column(note = "活动标题")
    protected String title;

    @Column(length = 64,note = "活动描述")
    protected String note;

    @Column(name="user_id",notNull = true,defVal = "0",note = "优惠活动所属人")
    protected Long userId;

    @Column(notNull = true,defVal = "1",note = "活动类型")
    protected Integer type;

    @Column(name = "coupon_Type", notNull = true, note = "优惠券类型，1:折扣券，2:代金券，3:租期券")
    protected Integer couponType;

    @Column(name = "coupon_money",notNull = true,defVal = "0",note = "优惠金额")
    protected Integer couponMoney;

    @Column(name = "coupon_discount",notNull = true,defVal = "0",note = "优惠折扣")
    protected Double couponDiscount;

    @Column(name = "coupon_day",notNull = true,defVal = "0",note = "优惠天数")
    protected Integer couponDay;

    @Column(name = "minimum_charge", notNull = true,defVal = "0", note = "最低消费金额")
    protected Integer minimumCharge;

    @Column(name = "use_range",notNull = true,defVal = "1",note = "使用范围，1:不限制，2:指定网点")
    protected Integer useRange;

    @Column(name = "use_limit", notNull = true, defVal = "1", note = "类型限制，1:不限制，2:限制业务类型")
    protected Integer useLimit;

    @Column(name = "business_type", note = "业务类型")
    protected String businessType;

    @Column(name = "start_date",notNull = true,note = "活动起始时间")
    protected Date startDate;

    @Column(name = "end_date",notNull = true,note = "活动结束时间")
    protected Date endDate;

    @Column(name = "coupon_count",notNull = true,defVal = "0",note = "优惠次数")
    protected Integer couponCount;

    @Column(notNull = true,defVal = "1",note = "活动状态")
    protected Integer state;

    @Column(name = "update_date", autoUpdateTime = true)
    protected Date updateDate;

    @Column(name = "create_date")
    protected Date createDate;

    @JoinField(name = "name",fromField = "user_id",toTable = "user_info",type = "LEFT")
    protected String userName;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getCouponType() {
        return couponType;
    }

    public void setCouponType(Integer couponType) {
        this.couponType = couponType;
    }

    public Integer getCouponMoney() {
        return couponMoney;
    }

    public void setCouponMoney(Integer couponMoney) {
        this.couponMoney = couponMoney;
    }

    public Double getCouponDiscount() {
        return couponDiscount;
    }

    public void setCouponDiscount(Double couponDiscount) {
        this.couponDiscount = couponDiscount;
    }

    public Integer getCouponDay() {
        return couponDay;
    }

    public void setCouponDay(Integer couponDay) {
        this.couponDay = couponDay;
    }

    public Integer getMinimumCharge() {
        return minimumCharge;
    }

    public void setMinimumCharge(Integer minimumCharge) {
        this.minimumCharge = minimumCharge;
    }

    public Integer getUseRange() {
        return useRange;
    }

    public void setUseRange(Integer useRange) {
        this.useRange = useRange;
    }

    public Integer getUseLimit() {
        return useLimit;
    }

    public void setUseLimit(Integer useLimit) {
        this.useLimit = useLimit;
    }

    public String getBusinessType() {
        return businessType;
    }

    public void setBusinessType(String businessType) {
        this.businessType = businessType;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Integer getCouponCount() {
        return couponCount;
    }

    public void setCouponCount(Integer couponCount) {
        this.couponCount = couponCount;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getCouponTypeName(){
        return ECouponType.note(this.couponType);
    }

    public String getTypeName(){
        return CouponActivityEnum.Type.note(this.type);
    }

    public String getStateName() {
        return CouponActivityEnum.State.note(this.state);
    }

    public String getUseRangeName() {
        return CouponActivityEnum.UseRange.note(this.useRange);
    }

    public String getUseLimitName() {
        return CouponActivityEnum.UseLimit.note(this.useLimit);
    }

    public String getCouponMoneyStr(){
        return NumberTools.getMoneyStr(this.couponMoney);
    }

    public String getMinimumChargeStr(){
        return NumberTools.getMoneyStr(this.minimumCharge);
    }

    public String getBusinessTypeName(){
        if(StringTools.isNotBlank(businessType)){
            return EBusinessType.note(this.businessType);
        }else{
            return "--";
        }
    }

    public String getCouponInfo() {
        if (ECouponType.VOUCHERS.index().equals(this.couponType)) {
            //代金券
            if (this.minimumCharge > 0) {
                return "满" + NumberTools.getMoneyStr(this.minimumCharge) + "元立减" + NumberTools.getMoneyStr(this.couponMoney) + "元优惠券";
            } else {
                return "消费立减" + NumberTools.getMoneyStr(this.couponMoney) + "元优惠券";
            }
        }else if(ECouponType.DISCOUNT_COUPON.index().equals(this.couponType)) {
            //折扣券
            if (this.minimumCharge > 0) {
                return "满" + NumberTools.getMoneyStr(this.minimumCharge) + "元打" + this.couponDiscount + "折优惠券";
            } else {
                return "消费打" + this.couponDiscount + "折优惠券";
            }
        }else if(ECouponType.COUPON_DAY.index().equals(this.couponType)) {
            return "免费" + this.couponDay + "天租金";
        }else{
            return "无优惠";
        }
    }
}
